function fileupload(div,box,filename,num,assign)
{


	div.fileupload({
		dataType: 'json',
		add: function (e, data) {
			var numItems = $('#fileuplade .list-img').length;
			if (numItems >= num) {
				layer.msg('图片只能提交一张');
				return false;
			}
			box.find('.progress .progress-bar-success').css('width', '0px');
			box.find('.progress').show();
			data.submit();
		},

		progressall: function (e, data) {
			var progress = parseInt(data.loaded / data.total * 100, 10);
			box.find('.progress .progress-bar-success').html(progress + '%');
			box.find('.progress .progress-bar-success').css('width',progress + '%');
		},



		done: function (e, data) {

			box.find('.progress').hide();
			var res = data.result;

			if(res.code != 1){
				layer.msg('上传失败，请重新上传');
			}else{

				var img = "'"+res.msg+"'";
				var html = '';
					html += '<div class="col-md-4 col-sm-12 col-xs-6 list-img">';
						html += '<div class="album-image" >';
							html += '<input type="hidden" name="'+filename+'" value="'+res.msg+'">';
							html += '<a href="javascript:;" onclick="lookImg('+img+')" class="thumb" data-action="edit" style="height: 120px;overflow: hidden;">';
								html += '<img src="'+res.msg+'" class="img-responsive"/>';
							html += '</a>';
							html += '<a href="#" class="name"><span>'+res.name+'</span></a>';
							html += '<div class="image-options">';
								html += '<a title="删除" href="javascript:;" class="deleteTheImg" data-action="trash" data-url="' + res.msg + '"><i class="fa fa-trash-o"></i></a>';
							html += '</div>';
						html += '<div>';
					html += '<div>';
				$('#'+assign).append(html);
			}
		}
	});
}

function lookImg(data)
{
	var img = {
		"title": "", //相册标题
		"id": 123, //相册id
		"start": 0, //初始显示的图片序号，默认0
		"data": [   //相册包含的图片，数组格式
			{
				"alt": "图片名",
				"pid": 666, //图片id
				"src": data, //原图地址
				"thumb": data //缩略图地址
			}
		]
	};

	layer.photos({
		photos:img //格式见API文档手册页
		,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
	});
}

$(function(){
	$(document).on('click','.deleteTheImg',function(e){
		//询问框
		var _this = $(this);
		layer.confirm('您确定要删除此图？', {
			btn: ['放弃','删除'] //按钮

		}, function(){
			layer.msg('我也觉得放弃的是正确的');

		}, function(){
			var imgUrl = _this.attr('data-url');
			var table = $("#table").val();
			var key1 = $("#key1").val();
			var key2 = $("#key2").val();
			var _token = $('input[name="_token"]').val();
			$.ajax({
				type:"post",
				url:"/delete/image",
				dataType:'json',
				data:'imgUrl='+imgUrl+'&table='+table+'&key1='+key1+'&key2='+key2+'&_token='+_token,
				success: function(json){
					if(json.code == 1){
						_this.parents(".list-img").remove();
						layer.msg('删除成功');
					}else{
						layer.msg('删除失败');
					}
				}
			});
		});
		
	});
});